//opens all the spectra in one directory, stacks them and shows the result
function documentTestSimple() {
	var dirPath = FileDialog.getExistingDirectory(Dir.home(), "Open Directory"),
		dir,	innerDirs,
		nmrItems, arrItem, doc,
		i, nmrPages = [], start, end;

	if (dirPath) {
		dir = new Dir(dirPath);
		innerDirs = dir.entryList("*", Dir.Dirs | Dir.NoDotAndDotDot, Dir.Name)
	}
	if (innerDirs.length === 0) {
		return;
	}
	innerDirs.sort(Dir.alphanumericPathsCompare)
	for (i = 0; i < innerDirs.length; ++i) {
		innerDirs[i] = dir.absPath + "/" + innerDirs[i];
	}

	function open(aDoc) {
		mainWindow.setBusy("Opening")
		serialization.importFile(innerDirs, "", aDoc);
		nmrItems = aDoc.itemsByName('NMR Spectrum');
		if (nmrItems.length !== innerDirs.length) {
			MessageBox.critical("Unable to open all the spectra");
			return;
		}
		for (i = 0; i < nmrItems.length; ++i) {
			nmrPages.push(nmrItems[i].page);
		}
		arrItem = nmr.createArrayedItem(nmrItems, true);
		aDoc.deletePages(nmrPages);
		mainWindow.endBusy();
	}

	function runNew() {
		doc = new Document();
		pag = new Page(doc.newPage());
		print("Page valid {0}".format(pag.isValid()));
		Application.lockDocument(doc);
		open(doc);
		serialization.save("/tmp/MyDoc.mnova", "mnova");
		mainWindow.addDocument(doc);
//		doc.destroyDocument();
		Application.unlockDocument();
	}

	start = new Date();
	print(start.toLocaleTimeString());
	runNew();
	start = new Date();
	print(start.toLocaleTimeString());
}	
